<script setup>
import { ref } from 'vue'
import { useRoute } from 'vue-router/composables'
const props = defineProps({
  items: {
    type: Array
  }
})
const route = useRoute()
const emit = defineEmits(['changeItem'])
const activeIndex = ref(
  Number(
    route.query?.defaultIndex
      ? route.query.defaultIndex
      : '0'
  )
)
const type = ref(route.query.type)
console.log(activeIndex)
const changeItem = (item, index) => {
  if (type.value == 'add') {
    return
  }
  activeIndex.value = index
  emit('changeItem', item, index)
}
</script>
<template>
  <div class="step-bar">
    <div
      v-for="(item, index) in items"
      :key="index"
      class="step-item"
      :class="{ active: activeIndex === index }"
    >
      <div class="step-arrow" v-if="activeIndex === index">
        <div class="arrow-down"></div>
      </div>
      <div class="step-circle-wrapper">
        <div
          class="step-circle"
          :class="{ active: activeIndex === index }"
          @click="changeItem(item, index)"
        >
          <div
            class="step-inner-circle"
            :class="{
              active: activeIndex === index,
              noClick: index !== 0 && type == 'add'
            }"
          ></div>
        </div>
      </div>
      <div
        class="step-name"
        :class="{
          active: activeIndex === index,
          noClick: index !== 0 && type == 'add'
        }"
      >
        {{ item }}
      </div>
      <div class="step-line"></div>
    </div>
  </div>
</template>
<style scoped>
.step-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 20px;
  margin: 0 30px;
}

.step-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  font-size: 16px;
  margin-bottom: 18px;
  flex: 1;
}

.step-circle-wrapper {
  margin-top: 10px;
}

.step-circle {
  width: 28px;
  height: 28px;
  background: #d0d8e150;
  /* border: 1px solid #d0d8e1; */
  border-radius: 50%;
  background-color: #d0d8e170;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
  position: relative;
}
.step-circle.active {
  background: #00baff50;
}
.step-inner-circle {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background-color: #c1cdda;
  display: flex;
  justify-content: center;
  align-items: center;
}

.step-inner-circle.active {
  background-color: #00baff;
}

.step-name {
  margin-top: 10px;
  text-align: center;
  font-size: 16px;
  color: #ccc;
}

.step-name.active {
  color: #00baff;
}

.step-line {
  width: 100%;
  height: 2px;
  background-color: #ccc;
  position: absolute;
  top: 23px;
  left: 0;
  border-top: 2px solid #ccc;
  z-index: 0;
}

.step-item:first-child .step-line {
  border-top: none;
}

.step-arrow {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  justify-content: center;
  align-items: center;
}

.arrow-down {
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid #00baff;
}
.noClick {
  cursor: not-allowed;
}
</style>
